package sanshui.system.trade.config.swagger;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger配置组件


 */
@Configuration
@EnableSwagger2
@ConfigurationProperties(prefix = "api.doc")
//@EnableSwaggerBootstrapUI
public class SwaggerConfig {

    //是否开启swagger，正式环境一般是需要关闭的，可根据springboot的多环境配置进行设置
    Boolean swaggerEnabled = true;

//    @Value("${server.port}")
//    private String port;

//    @Value("${server.domain}")
//    private String domain;
    @Bean("trade")
    public Docket create2RestTradeApis() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("trade")
                .apiInfo(apiInfo())
                // 是否开启
                .enable(swaggerEnabled)
                .select()
                // 扫描的路径包
                .apis(RequestHandlerSelectors.basePackage("sanshui.system.trade"))
                // 指定路径处理PathSelectors.any()代表所有的路径
                .build()
//                .globalOperationParameters(pars) // 针对单个url的验证 如果需要的话
                .pathMapping("/");
    }
    private ApiInfo apiInfo() {
        // http://localhost:8080/doc.html
        return new ApiInfoBuilder()
                .title(" Java")
                .description("test")
                .termsOfServiceUrl("http://host:port")
                .version("1.0.1").build();
    }

}
